package tour.spring.web.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import tour.spring.bc.bo.impl.ClientBoImpl;
import tour.spring.bc.model.Client;

@Service("userAthService")
public class UserAuthenticationServiceImpl implements UserDetailsService{
	
	
	@Autowired
	ClientBoImpl clientBo;
	
	public UserDetails loadUserByUsername(String login)throws UsernameNotFoundException{
		Client client = clientBo.getClientByLogin(login);
		
		if(client == null) {
	        throw new UsernameNotFoundException("User for username " + login + "was not found.");
	    }
		return client.getUserRole().getUserDetails(client.getLogin(), client.getPassword());
	}
}
 